package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.YdFunction;
import com.zhentao.domain.YdUser;
import com.zhentao.mapper.YdFunctionMapper;
import com.zhentao.service.YdUserService;
import com.zhentao.mapper.YdUserMapper;
import com.zhentao.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86131
* @description 针对表【yd_user(用户表)】的数据库操作Service实现
* @createDate 2024-10-20 20:24:32
*/
@Service
public class YdUserServiceImpl extends ServiceImpl<YdUserMapper, YdUser>
    implements YdUserService,UserDetailsService{

    @Autowired
    private YdFunctionMapper ydFunctionMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        YdUser ydUser = this.getOne(Wrappers.<YdUser>lambdaQuery().eq(YdUser::getUsername, username));
        List<String> perms = ydFunctionMapper.showPerms(ydUser);
        ydUser.setPerms(perms);
        return ydUser;
    }

    @Autowired
    private YdUserMapper ydUserMapper;
    @Override
    public Result userList() {
        List<YdUser> ydUsers = ydUserMapper.userList();
        return Result.success(ydUsers);

    }}
